const loginModel = require("../../model/user/login");
async function login(req, res) {
    const data = await loginModel.login(req.body);
    const json = {
        code: data.code,
        message: data.msg,
        data: data.result !== undefined ? data.result : {},
    };

    res.send(json);
}
async function register(req, res) {
    const data = await loginModel.register(req.body);
    const json = {
        code: data.code,
        message: data.msg,
    };
    res.send(json);
}
async function checkUserName(req, res) {
    const result = await loginModel.checkUserName(req.query.username);
    let json = {};
    if (result == true) {
        json = {
            code: 0,
            message: "用户名已存在",
        };
    } else {
        json = {
            code: 1,
            message: "用户名可用",
        };
    }
    res.send(json)
}
module.exports = {
    login,
    register,
    checkUserName
};
